 alter table "Appointment" drop column if exists "PayTypeId";
 alter table "Appointment"
 add column if not exists "PayTypeId" integer references "PayType"("PayTypeId");
--------------------------------------
ALTER TABLE "PayType"
ALTER COLUMN "PayTypeValue"  TYPE varchar(255);
-------------------------------------------------------

with T as(
 select A."AppointmentId",PT."PayTypeId" from "Appointment" A 
  join "PayType" PT on lower(A."PaymentType") = lower(PT."PayTypeValue")
) 
update "Appointment" P set "PayTypeId" = T."PayTypeId" from T where P."AppointmentId" = T."AppointmentId";

--------------------------------------------------------